package com.zhouhailin;

import java.util.Optional;
import java.util.function.Predicate;

/**
 * 过滤值
 *
 * @Author zhouhailin
 * @date 2023/1/19 10:46
 */
public class FilterOptionalDemo {
    public static void main(String[] args) {
        String password = "12345";
        Optional<String> opt = Optional.ofNullable(password);
        System.out.println(opt.filter(pwd -> pwd.length() > 6).isPresent());

        // 要求密码是 6到10 位
        Predicate<String> len6 = pwd -> pwd.length() > 6;
        Predicate<String> len10 = pwd -> pwd.length() < 10;

        password = "1234567";
        opt = Optional.ofNullable(password);
        boolean result = opt.filter(len6.and(len10)).isPresent();
        System.out.println(result);
    }
}
